//
//  LogingViewController.m
//  HMShoperApp
//
//  Created by chirui on 2018/6/21.
//  Copyright © 2018年 Shui. All rights reserved.
//

#import "LogingViewController.h"
#import "ForgetPwViewController.h"
#import "TabBarVc.h"
#import "RegistUserViewController.h"
#import "FirstPerfectViewController.h"

@interface LogingViewController ()
@property (weak, nonatomic) IBOutlet UITextField *phoneText;
@property (weak, nonatomic) IBOutlet UITextField *passWordText;
@property (weak, nonatomic) IBOutlet UIButton *reginBtn;
@property (weak, nonatomic) IBOutlet UIView *bgView;

@end

@implementation LogingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
  
    _reginBtn.layer.cornerRadius = 45/2.f;
    _reginBtn.layer.masksToBounds = YES;
    _reginBtn.layer.borderWidth = 0.5f;
    _reginBtn.layer.borderColor = MainColor.CGColor;
    
    _bgView.layer.cornerRadius = 5.f;
    _bgView.layer.masksToBounds = YES;
}

- (IBAction)forget:(UIButton *)sender {
    ForgetPwViewController * forget = [[ForgetPwViewController   alloc]init];
    
    [self presentViewController:forget animated:YES completion:^{
        
    }];
}
- (IBAction)reginBtnClick:(UIButton *)sender {
    RegistUserViewController * regist = [[RegistUserViewController   alloc]init];
    
    [self presentViewController:regist animated:YES completion:^{
        
    }];
    
}

- (IBAction)sureBtnClick:(UIButton *)sender {
    
    if (_phoneText.text.length!=11) {
        
        SHuiMBhudTextTimeStr(@"请输入正确的手机号码");
        return;
    }
    if (_passWordText.text.length<=0) {
        
        SHuiMBhudTextTimeStr(@"请输入密码");
        return;
    }
   
    [self logingRequest];
}

-(void)logingRequest{
    
    NSDictionary * dic = @{@"userAccount":_phoneText.text,
                           @"userPassword":_passWordText.text
                           };
    [PostNetWorking postNetWorkingStr:RequestUrlStr(user_login_api) andparameters:dic Success:^(id responseObject) {
        
        if (codeSucess) {
            
            USER_DEFAULTSet(responseObject[@"datas"][@"mid"], @"mid");
            USER_DEFAULTSet(responseObject[@"datas"][@"token"], @"token");
            USER_DEFAULTSet(responseObject[@"datas"][@"username"], @"username");
            USER_DEFAULTSet(responseObject[@"datas"][@"nickname"], @"nickname");
            USER_DEFAULTSet(responseObject[@"datas"][@"header"], @"header");
            USER_DEFAULTSet(responseObject[@"datas"][@"if_complete"], @"if_complete");
            // 绑定极光推送别名
            [[NSNotificationCenter defaultCenter] postNotificationName:@"bindAlia" object:@"YES"];
            USER_DEFAULTSet(@"OK", @"enter");
            USER_DEFAULTSet(@"OK", @"tokenVerify");
            if ([responseObject[@"datas"][@"if_complete"] isEqualToString:@"no"]) {
                FirstPerfectViewController * perfect =[[FirstPerfectViewController alloc]init];
                [self presentViewController:perfect animated:YES completion:^{
                    
                }];
                
            }else {
            TabBarVc * tabbar  =[[TabBarVc alloc]init];
            [UIApplication sharedApplication].keyWindow.rootViewController = tabbar;
            }
        }else {
            
            SHuiMBhudTextTimeStr(responseObject[@"mark"]);
        }
        
    } failed:^(NSError *error) {
       
        SHuiMBhudTextNetError;
    }];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
